package edu.gatech.geochat.model;

import java.util.ArrayList;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import edu.gatech.geochat.GeoChatActivity;
import edu.gatech.geochat.database.Storage;

public class User {
	private String username;
	private String password;
	private String email;
	private String found = "";

	public static final double displayRadius = 25;
	public static final double maxDistance = 100;
	private static Iterable<GeoMessage> closeMessages;
	private static Location currentLocation;

	public User(String username, String password, String email) {
		this.username = username;
		this.password = password;
		this.email = email;

		updateCloseMessages();
	}
	
	public void setLocation(Location location) {
		this.currentLocation = location;
	}
	
	public void updateCloseMessages() {
		closeMessages = Storage.getInstance().getNearbyLocations(this, maxDistance);
	}

	public String getFoundText() {
		return found;
	}

	public void setFound(String found) {
		this.found = found;
	}

	public String[] founds() {
		if (found.indexOf(',') < 0)
			return new String[] {};
		return found.replaceAll("\\s+", "").split(",");
	}

	public void found(String f) {
		if (found.indexOf(',') > 0)
			found += ",";
		found += f;
	}

	public String getLatitude() {
		if (currentLocation == null)
			return "0";
		return String.valueOf(currentLocation.getLatitude());
	}

	public String getLongitude() {
		if (currentLocation == null)
			return "0";
		return String.valueOf(currentLocation.getLongitude());
	}

	public String getUsername() {
		return username;
	}

	public String getPassword() {
		return password;
	}

	public String getEmail() {
		return email;
	}

	public static Location getLocation() {
		return currentLocation;
	}

	public static Iterable<GeoMessage> getMessages() {
		if (closeMessages != null)
			return closeMessages;
		else {
			Log.d("User", "messages null");
			return new ArrayList<GeoMessage>();
		}
	}
}
